<template>
	<view :style="colorStyle">
		<view class='sign' :style="colorStyle">
			<view class='header bgcolor'>
				<view class='pointsbox'>
					<view class='userpoints'>{{memberinfo.points || ''}}
					</view>
					<view class='pointstitle'>我的{{lang.points}}</view>
				</view>
			</view>
			<view class='wrapper'>
				<view class='list acea-row row-between-wrapper'>
					<view class='item' v-for="(item,index) in signinConfigList" :key="index">
						<view :class='(index+1) == signinConfigList.length ? "rewardTxt" : ""'>
							{{(item.day=='第七天' || item.day=='第7天')?'奖励':item.day}}
						</view>
						<view class='venus'
							:class="(index + 1 === signinConfigList.length ? 'venusSelect' : '') + ' ' +(sign_index >= index + 1 ? 'venusSelect' : '')">
						</view>
						<view class='num' :class="sign_index >= index + 1 ? 'on' : ''">+{{item.number}}</view>
					</view>
				</view>
				<button class='but bg-color on' v-if="memberinfo.is_day_sgin">今天已签到</button>
				<form @submit="goSign" v-else>
					<button class='but bg-color' formType="submit">立即签到</button>
				</form>
			</view>
			<view class='wrapper wrapper2'>
				<view class='tip'>已累计签到</view>
				<view class='list2 acea-row row-center row-bottom'>
					<view class='item'>{{signCount[0] || 0}}</view>
					<view class='item'>{{signCount[1] || 0}}</view>
					<view class='item'>{{signCount[2] || 0}}</view>
					<view class='item'>{{signCount[3] || 0}}</view>
					<view class='data'>天</view>
				</view>
				<view class='tip2'>据说连续签到第{{day}}天可获得超额{{lang.points}}，一定要坚持签到哦~~~</view>
				<view class='list3'>
					<view class='item acea-row' v-for="(item,index) in signList" :key="index">
						<view>
							<view class='name line1'>{{item.title}}</view>
							<view class='data'>{{item.create_time}}</view>
						</view>
						<view class='num'>+{{item.number}}</view>
					</view>
				</view>
			</view>
			<view class='signTip acea-row row-center-wrapper' :class='active==true?"on":""'>
				<view class='signTipLight loadingpic'></view>
				<view class='signTipCon'>
					<view class="signHeight">
						<image src="../../../static/images/signH.png"></image>
					</view>
					<view class='state'>签到成功</view>
					<view class='points'>获得{{getpoints}}{{lang.points}}</view>
					<view class='signTipBnt' @click='close'>好的</view>
				</view>
			</view>
			<view class='mask' @touchmove.stop.prevent="false" :hidden='active==false'></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lang:{},
				colorStyle: '--view-theme: rgba(233,51,35,1);',
				active: false,
				pagestyleconfig: [],
				memberinfo: {},
				signCount: [],
				signinConfigList: [],
				signList: [],
				getpoints: 0,
				day: 0,
				sign_index: 0
			};
		},
		watch: {},
		onLoad() {
			let _this = this;
			_this.$request.get('Lang.getlang').then(res => {
				if (res.errno == 0) {
					_this.lang = res.data;
				}
			});
			_this.$request.post('config', {
				mo: 'pagestyle'
			}).then(res => {
				if (res.errno == 0) {
					_this.pagestyleconfig = res.data
					_this.colorStyle = '--view-theme: '+ _this.pagestyleconfig.appstylecolor + ';';
				}
			});
			_this.$util.getUserInfo(function(userInfo) {
				_this.$request.get('signin.memberinfo', {
					samkey: (new Date()).valueOf()
				}).then(res => {
					if (res.errno == 0) {
						let sum_sgin_day = res.data.sum_sgin_day;
						_this.memberinfo = res.data;
						_this.signCount = _this.PrefixInteger(sum_sgin_day, 4);
						_this.sign_index = res.data.sign_index;
					}
				});
			});
			this.getSigninConfig();
			this.getSignList();

		},
		methods: {
			/**
			 * 获取签到配置
			 */
			getSigninConfig: function() {
				let _this = this;
				_this.$request.get('Signin.signinconfig').then(res => {
					if (res.errno == 0) {
						_this.signinConfigList = res.data;
						_this.day = _this.Rp(res.data.length);
					}
				});
			},

			/**
			 * 获取签到列表
			 * 
			 */
			getSignList: function() {
				let _this = this;
				_this.$request.get('Signin.list').then(res => {
					if (res.errno == 0) {
						_this.signList = res.data;
					}
				});
			},
			/**
			 * 数字转中文
			 * 
			 */
			Rp: function(n) {
				let cnum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
				let s = '';
				n = '' + n; // 数字转为字符串
				for (let i = 0; i < n.length; i++) {
					s += cnum[parseInt(n.charAt(i))];
				}
				return s;
			},
			/**
			 * 数字分割为数组
			 * @param int num 需要分割的数字
			 * @param int length 需要分割为n位数组
			 */
			PrefixInteger: function(num, length) {
				return (Array(length).join('0') + num).slice(-length).split('');
			},

			/**
			 * 用户签到
			 */
			goSign: function(e) {
				let that = this;
				if (that.memberinfo.is_day_sgin) {
					this.tui.toast("您今日已签到");
					return
				} else {
					that.$request.get('signin.add').then(res => {
						if (res.errno == 0) {
							that.active = true;
							that.memberinfo = res.data;
							that.sign_index = that.memberinfo.sign_index;
							that.getpoints = that.memberinfo.getpoints;
							that.signCount = that.PrefixInteger(that.memberinfo.sum_sgin_day, 4);
							that.getSignList();

						}
					});
				}
			},
			/**
			 * 关闭签到提示
			 */
			close: function() {
				this.active = false;
			}
		},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 200);
		},
	}
</script>

<style scoped lang="scss">
	view {
		box-sizing: border-box;
	}

	.acea-row.row-between-wrapper {
		-o-box-align: center;
		align-items: center;
		-o-box-pack: justify;
		justify-content: space-between
	}

	.acea-row {
		display: flex;
		-webkit-box-lines: multiple;
		-moz-box-lines: multiple;
		-o-box-lines: multiple;
		flex-wrap: wrap
	}
	.acea-row.row-center-wrapper {
		-webkit-box-align: center;
		-moz-box-align: center;
		-o-box-align: center;
		-ms-flex-align: center;
		-webkit-align-items: center;
		align-items: center;
		-webkit-box-pack: center;
		-moz-box-pack: center;
		-o-box-pack: center;
		-ms-flex-pack: center;
		-webkit-justify-content: center;
		justify-content: center
	}

	.acea-row.row-center {
		-o-box-pack: center;
		justify-content: center
	}

	.acea-row.row-top {
		-o-box-align: start;
		align-items: flex-start
	}

	.acea-row.row-bottom {
		-o-box-align: end;
		align-items: flex-end
	}

	.line1 {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap
	}

	.acea-row.row-bottom {
		-o-box-align: end;
		align-items: flex-end
	}

	.loadingpic {
		-webkit-animation: load 3s linear 1s infinite;
		animation: load 3s linear 1s infinite;
		--webkit-animation: load 3s linear 1s infinite
	}

	.bgcolor {
		background-color: var(--view-theme);
	}

	.sign .header {
		width: 100%;
		height: 310rpx;
	}

	.pointsbox {
		color: #FFF;
		padding: 60rpx 0 0 0;
		border-radius: 15rpx;
		padding-bottom: 80rpx;
		position: relative;
	}

	.userpoints {
		font-size: 68rpx;
		text-align: center;
		margin: 0 auto;
	}

	.pointstitle {
		font-size: 24rpx;
		text-align: center;
		margin: 0 auto;
	}

	.sign .wrapper {
		background-color: #fff;
		margin: -80rpx 20rpx 0 20rpx;
		border-radius: 15rpx;
		padding-bottom: 80rpx;
		position: relative;
	}

	.sign .wrapper .list {
		padding: 0 30rpx;
		height: 240rpx;
	}

	.sign .wrapper .list .item {
		font-size: 22rpx;
		color: #8a8886;
		text-align: center;
	}

	.sign .wrapper .list .item .rewardTxt {
		width: 74rpx;
		height: 32rpx;
		background-color: #f4b409;
		border-radius: 16rpx;
		font-size: 20rpx;
		color: #a57d3f;
		line-height: 32rpx;
	}

	.sign .wrapper .list .item .num {
		font-size: 30rpx;
		color: #999;
	}

	.sign .wrapper .list .item .num.on {
		color: #ff9000;
	}

	.sign .wrapper .list .item .venus {
		margin: 10rpx auto;
		background-image: url('');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		width: 56rpx;
		height: 56rpx;
	}

	.sign .wrapper .list .item .venus.venusSelect {
		background-image: url('');
	}

	.sign .wrapper .list .item .venus.reward {
		background-image: url('');
		width: 75rpx;
		height: 56rpx;
	}

	.sign .wrapper .but {
		width: 400rpx;
		height: 76rpx;
		font-size: 30rpx;
		line-height: 76rpx;
		color: #fff;
		border-radius: 50rpx;
		text-align: center;
		margin: 0 auto;
	}
	.mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: #000;
		opacity: .5;
		z-index: 5
	}

	.sign .wrapper .but.on {
		background-color: #999 !important;
	}

	.sign .wrapper2 {
		margin-top: 15rpx;
		padding: 73rpx 0 0 0;
	}

	.sign .wrapper2 .tip {
		font-size: 30rpx;
		color: #666;
		text-align: center;
	}

	.sign .wrapper2 .list2 {
		margin: 45rpx 0 49rpx 0;
	}

	.sign .wrapper2 .list2 .item {
		border-radius: 10rpx;
		background-color: var(--view-theme);
		width: 80rpx;
		height: 116rpx;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		color: #fff;
		font-size: 72rpx;
		text-align: center;
		line-height: 116rpx;
		margin-right: 19rpx;
		background-image: url('');
	}

	.sign .wrapper2 .list2 .data {
		font-size: 30rpx;
		color: #232323;
	}

	.sign .wrapper2 .tip2 {
		font-size: 30rpx;
		color: #999999;
		padding: 0 55rpx;
		text-align: center;
		line-height: 1.5;
	}

	.sign .list3 {
		margin: 45rpx 37rpx 0 37rpx;
		border-top: 1px dashed #eee;
	}

	.sign .list3 .item {
		align-items: center;
		justify-content: space-between;
		border-bottom: 1px solid #eee;
		height: 130rpx;
	}

	.sign .list3 .item .name {
		color: #232323;
		font-size: 30rpx;
		width: 400rpx;
	}

	.sign .list3 .item .data {
		font-size: 24rpx;
		color: #bbbbbb;
		margin-top: 9rpx;
	}

	.sign .list3 .item .num {
		font-size: 36rpx;
		font-family: 'Guildford Pro';
		color: #E93323;
	}

	.sign .list3 .loading {
		font-size: 26rpx;
		color: #282828;
		height: 97rpx;
		line-height: 97rpx;
		text-align: center;
	}

	.sign .list3 .loading .iconfont {
		font-size: 25rpx;
		color: #212121;
		vertical-align: 2rpx;
		margin-left: 10rpx;
	}

	.sign .signTip {
		width: 644rpx;
		height: 645rpx;
		position: fixed;
		top: 50%;
		left: 50%;
		margin-left: -322rpx;
		margin-top: -322.5rpx;
		z-index: 99;
		text-align: center;
		transition: all 0.3s ease-in-out 0s;
		opacity: 0;
		transform: scale(0);
	}

	.sign .signTip .signTipLight {
		background-image: url('');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		width: 100%;
		height: 100%;
	}

	.sign .signTip.on {
		opacity: 1;
		transform: scale(1);
	}

	.sign .signTip .signTipCon {
		background: url('') no-repeat;
		background-size: 100% 100%;
		width: 420rpx;
		height: 410rpx;
		margin-top: -642rpx;
		position: relative;
		background-color: var(--view-theme);
		border-radius: 10rpx;
	}

	.sign .signTip .signTipCon .signHeight {
		width: 134rpx;
		height: 120rpx;
		position: absolute;
		left: 50%;
		margin-left: -67rpx;
		top: -60rpx;
	}

	.sign .signTip .signTipCon .signHeight image {
		width: 100%;
		height: 100%;
	}

	.sign .signTip .signTipCon .state {
		font-size: 34rpx;
		color: #fff;
		margin-top: 150rpx;
	}

	.sign .signTip .signTipCon .points {
		font-size: 30rpx;
		color: rgba(255, 255, 255, 0.6);
		margin-top: 9rpx;
	}

	.sign .signTip .signTipCon .signTipBnt {
		font-size: 30rpx;
		color: #fff;
		width: 260rpx;
		height: 76rpx;
		background-color: #f8d168;
		border-radius: 38rpx;
		line-height: 76rpx;
		margin: 48rpx auto 0 auto;
	}

	.bg-color {
		background-color: var(--view-theme) !important
	}
</style>